package day04;

/*
 * Author: JacksonCoder
 * FileName: PassByValueDemo
 * Version: 1.0.0
 * Date: 2025/4/11
 */

class Person {
    private String name;

    public Person(String name) {
        this.name = name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName(){
        return name;
    }
}

public class PassByValueDemo {
    // 值传递
    public static void main(String[] args) {
        int a = 10;
        modify(a);
        System.out.println("a = " + a);

        Person p = new Person("alex");
        System.out.println("p.name = "+p.getName());   // alex
        changeName(p);
        System.out.println("p.name = "+p.getName());   // Jackson

        Person p2 = new Person("alice");
        System.out.println("p.name = "+ p2.getName());   // alice
        register(p2);
        System.out.println("p.name = "+ p2.getName());   // alice

    }

    public static void register(Person person){
        person = new Person("David"); // 仅修改了内部引用，不影响外部
    }

    public static void changeName(Person person){
        person.setName("Jackson");
    }

    public static int modify(int a ){
        a = 100;
        return a;
    }

    public static int add(int a, int b){
        return a + b;
    }

}
